﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace NS.DAL
{
	/// <summary>
	/// 数据访问类:Shops
	/// </summary>
	public partial class Shops
	{
		public Shops()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ShopID", "Shops"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ShopID)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@ShopID", SqlDbType.Int,4)
};
			parameters[0].Value = ShopID;

			int result= DbHelperSQL.RunProcedure("ns_Shops_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(NS.Model.Shops model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@ShopID", SqlDbType.Int,4),
					new SqlParameter("@ShopName", SqlDbType.NVarChar,50),
					new SqlParameter("@ShopSlogan", SqlDbType.NVarChar,100),
					new SqlParameter("@ShopIntro", SqlDbType.NVarChar,500),
					new SqlParameter("@ShopNotice", SqlDbType.NVarChar,500),
					new SqlParameter("@ShopAccount", SqlDbType.NVarChar,50),
					new SqlParameter("@Password", SqlDbType.NVarChar,100),
					new SqlParameter("@QQ", SqlDbType.NVarChar,15),
					new SqlParameter("@Age", SqlDbType.Int,4),
					new SqlParameter("@Location", SqlDbType.NVarChar,20),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@Weight", SqlDbType.Int,4),
					new SqlParameter("@Job", SqlDbType.NVarChar,50),
					new SqlParameter("@OnlineTime", SqlDbType.NVarChar,100),
					new SqlParameter("@AddTime", SqlDbType.DateTime),
					new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
					new SqlParameter("@IsAvailable", SqlDbType.Int,4),
					new SqlParameter("@IsDeleted", SqlDbType.Int,4),
					new SqlParameter("@DeletedTime", SqlDbType.DateTime)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.ShopName;
			parameters[2].Value = model.ShopSlogan;
			parameters[3].Value = model.ShopIntro;
			parameters[4].Value = model.ShopNotice;
			parameters[5].Value = model.ShopAccount;
			parameters[6].Value = model.Password;
			parameters[7].Value = model.QQ;
			parameters[8].Value = model.Age;
			parameters[9].Value = model.Location;
			parameters[10].Value = model.Height;
			parameters[11].Value = model.Weight;
			parameters[12].Value = model.Job;
			parameters[13].Value = model.OnlineTime;
			parameters[14].Value = model.AddTime;
			parameters[15].Value = model.LastUpdateTime;
			parameters[16].Value = model.IsAvailable;
			parameters[17].Value = model.IsDeleted;
			parameters[18].Value = model.DeletedTime;

			DbHelperSQL.RunProcedure("ns_Shops_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(NS.Model.Shops model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@ShopID", SqlDbType.Int,4),
					new SqlParameter("@ShopName", SqlDbType.NVarChar,50),
					new SqlParameter("@ShopSlogan", SqlDbType.NVarChar,100),
					new SqlParameter("@ShopIntro", SqlDbType.NVarChar,500),
					new SqlParameter("@ShopNotice", SqlDbType.NVarChar,500),
					new SqlParameter("@ShopAccount", SqlDbType.NVarChar,50),
					new SqlParameter("@Password", SqlDbType.NVarChar,100),
					new SqlParameter("@QQ", SqlDbType.NVarChar,15),
					new SqlParameter("@Age", SqlDbType.Int,4),
					new SqlParameter("@Location", SqlDbType.NVarChar,20),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@Weight", SqlDbType.Int,4),
					new SqlParameter("@Job", SqlDbType.NVarChar,50),
					new SqlParameter("@OnlineTime", SqlDbType.NVarChar,100),
					new SqlParameter("@AddTime", SqlDbType.DateTime),
					new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
					new SqlParameter("@IsAvailable", SqlDbType.Int,4),
					new SqlParameter("@IsDeleted", SqlDbType.Int,4),
					new SqlParameter("@DeletedTime", SqlDbType.DateTime)};
			parameters[0].Value = model.ShopID;
			parameters[1].Value = model.ShopName;
			parameters[2].Value = model.ShopSlogan;
			parameters[3].Value = model.ShopIntro;
			parameters[4].Value = model.ShopNotice;
			parameters[5].Value = model.ShopAccount;
			parameters[6].Value = model.Password;
			parameters[7].Value = model.QQ;
			parameters[8].Value = model.Age;
			parameters[9].Value = model.Location;
			parameters[10].Value = model.Height;
			parameters[11].Value = model.Weight;
			parameters[12].Value = model.Job;
			parameters[13].Value = model.OnlineTime;
			parameters[14].Value = model.AddTime;
			parameters[15].Value = model.LastUpdateTime;
			parameters[16].Value = model.IsAvailable;
			parameters[17].Value = model.IsDeleted;
			parameters[18].Value = model.DeletedTime;

			DbHelperSQL.RunProcedure("ns_Shops_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ShopID)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@ShopID", SqlDbType.Int,4)
};
			parameters[0].Value = ShopID;

			DbHelperSQL.RunProcedure("ns_Shops_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ShopIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Shops ");
			strSql.Append(" where ShopID in ("+ShopIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NS.Model.Shops GetModel(int ShopID)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@ShopID", SqlDbType.Int,4)
};
			parameters[0].Value = ShopID;

			NS.Model.Shops model=new NS.Model.Shops();
			DataSet ds= DbHelperSQL.RunProcedure("ns_Shops_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ShopID"]!=null && ds.Tables[0].Rows[0]["ShopID"].ToString()!="")
				{
					model.ShopID=int.Parse(ds.Tables[0].Rows[0]["ShopID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ShopName"]!=null && ds.Tables[0].Rows[0]["ShopName"].ToString()!="")
				{
					model.ShopName=ds.Tables[0].Rows[0]["ShopName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ShopSlogan"]!=null && ds.Tables[0].Rows[0]["ShopSlogan"].ToString()!="")
				{
					model.ShopSlogan=ds.Tables[0].Rows[0]["ShopSlogan"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ShopIntro"]!=null && ds.Tables[0].Rows[0]["ShopIntro"].ToString()!="")
				{
					model.ShopIntro=ds.Tables[0].Rows[0]["ShopIntro"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ShopNotice"]!=null && ds.Tables[0].Rows[0]["ShopNotice"].ToString()!="")
				{
					model.ShopNotice=ds.Tables[0].Rows[0]["ShopNotice"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ShopAccount"]!=null && ds.Tables[0].Rows[0]["ShopAccount"].ToString()!="")
				{
					model.ShopAccount=ds.Tables[0].Rows[0]["ShopAccount"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Password"]!=null && ds.Tables[0].Rows[0]["Password"].ToString()!="")
				{
					model.Password=ds.Tables[0].Rows[0]["Password"].ToString();
				}
				if(ds.Tables[0].Rows[0]["QQ"]!=null && ds.Tables[0].Rows[0]["QQ"].ToString()!="")
				{
					model.QQ=ds.Tables[0].Rows[0]["QQ"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Age"]!=null && ds.Tables[0].Rows[0]["Age"].ToString()!="")
				{
					model.Age=int.Parse(ds.Tables[0].Rows[0]["Age"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Location"]!=null && ds.Tables[0].Rows[0]["Location"].ToString()!="")
				{
					model.Location=ds.Tables[0].Rows[0]["Location"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Height"]!=null && ds.Tables[0].Rows[0]["Height"].ToString()!="")
				{
					model.Height=int.Parse(ds.Tables[0].Rows[0]["Height"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Weight"]!=null && ds.Tables[0].Rows[0]["Weight"].ToString()!="")
				{
					model.Weight=int.Parse(ds.Tables[0].Rows[0]["Weight"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Job"]!=null && ds.Tables[0].Rows[0]["Job"].ToString()!="")
				{
					model.Job=ds.Tables[0].Rows[0]["Job"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OnlineTime"]!=null && ds.Tables[0].Rows[0]["OnlineTime"].ToString()!="")
				{
					model.OnlineTime=ds.Tables[0].Rows[0]["OnlineTime"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AddTime"]!=null && ds.Tables[0].Rows[0]["AddTime"].ToString()!="")
				{
					model.AddTime=DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["LastUpdateTime"]!=null && ds.Tables[0].Rows[0]["LastUpdateTime"].ToString()!="")
				{
					model.LastUpdateTime=DateTime.Parse(ds.Tables[0].Rows[0]["LastUpdateTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IsAvailable"]!=null && ds.Tables[0].Rows[0]["IsAvailable"].ToString()!="")
				{
					model.IsAvailable=int.Parse(ds.Tables[0].Rows[0]["IsAvailable"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IsDeleted"]!=null && ds.Tables[0].Rows[0]["IsDeleted"].ToString()!="")
				{
					model.IsDeleted=int.Parse(ds.Tables[0].Rows[0]["IsDeleted"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DeletedTime"]!=null && ds.Tables[0].Rows[0]["DeletedTime"].ToString()!="")
				{
					model.DeletedTime=DateTime.Parse(ds.Tables[0].Rows[0]["DeletedTime"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ShopID,ShopName,ShopSlogan,ShopIntro,ShopNotice,ShopAccount,Password,QQ,Age,Location,Height,Weight,Job,OnlineTime,AddTime,LastUpdateTime,IsAvailable,IsDeleted,DeletedTime ");
			strSql.Append(" FROM Shops ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ShopID,ShopName,ShopSlogan,ShopIntro,ShopNotice,ShopAccount,Password,QQ,Age,Location,Height,Weight,Job,OnlineTime,AddTime,LastUpdateTime,IsAvailable,IsDeleted,DeletedTime ");
			strSql.Append(" FROM Shops ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Shops";
			parameters[1].Value = "ShopID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

